import 'package:flutter/material.dart';
import 'package:flutter2/utils/string.dart';
import 'package:flutter2/widget/base/base_container.dart';
import 'package:flutter2/widget/base/normal_text.dart';
import 'package:flutter2/widget/title_bar.dart';
import 'package:get/get.dart';
import 'package:package_info_plus/package_info_plus.dart';

class AboutController extends GetxController {
  var version = "".obs;

  @override
  void onReady() async {
    super.onReady();
    PackageInfo info = await PackageInfo.fromPlatform();
    version.value = info.version;
    update();
  }
}

class AboutPage extends StatelessWidget {
  AboutPage({super.key});

  final AboutController controller = Get.put(AboutController());

  @override
  Widget build(BuildContext context) {
    return GetBuilder<AboutController>(
      builder: (controller) => Scaffold(
        appBar: TitleBar.buildAppBar(title: "关于"),
        body: SizedBox(
          width: double.infinity,
          height: null,
          child: Column(
            mainAxisSize: MainAxisSize.min,
            crossAxisAlignment: CrossAxisAlignment.center,
            children: [
              SizedBox(
                height: 50,
              ),
              BaseContainer(
                click: () {
                  controller.version.value = "2.0.0";
                  controller.update();
                },
                backgroundImg: "ic_splash".toImage(),
                width: 100,
                height: 100,
              ),
              SizedBox(
                height: 20,
              ),
              NormalText(
                text: "V${controller.version}",
              ),
            ],
          ),
        ),
      ),
      assignId: true,
    );
  }
}
